package com.sumansoul.inputmsgdialog;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {

    //输入弹窗
    private InputTextMsgDialog inputTextMsgDialog;
    private Timer timer;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btn = findViewById(R.id.btn);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showSoft();
            }
        });




    }




    private void showSoft() {
        try {
            if (inputTextMsgDialog == null) {
                inputTextMsgDialog = new InputTextMsgDialog(MainActivity.this, R.style.dialog_center);
                inputTextMsgDialog.setHint("请输入聊天内容");
            }

            if (timer == null) {
                timer = new Timer();
            }
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            inputTextMsgDialog.showKeyboard();
                        }
                    });
                }
            }, 100);


            inputTextMsgDialog.show();
            inputTextMsgDialog.setmOnTextSendListener(new InputTextMsgDialog.OnTextSendListener() {
                @Override
                public void onInputTextString(String msg) {
                    //  LogUtils.d("msg===========" + msg);
                }

                @Override
                public void onClickSend(String message) {
                    String comment = message.replace(" ", "");
                    if (!TextUtils.isEmpty(comment)) {
                        Toast.makeText(MainActivity.this, comment, Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(MainActivity.this, "请输入聊天内容", Toast.LENGTH_SHORT).show();
                    }

                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
